package com.sx.manage.controller.data.auth;

import java.io.IOException;

import javax.annotation.Resource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sx.manage.controller.base.MBaseController;
import com.sx.manage.service.data.auth.MDataAuthWebService;
import com.sx.manage.servlet.ViewAndModel;
import com.sx.model.manage.mybatis.form.data.auth.MDataAuthorityForm;
import com.sx.model.manage.mybatis.vo.data.auth.MDataAuthorityVO;
import com.sx.model.manage.mybatis.vo.result.ResultBooleanVO;
import com.sx.model.manage.mybatis.vo.result.ResultListVO;

@Controller
@RequestMapping("/dataAuth")
public class MDataAuthController extends MBaseController {

	private Logger log = LoggerFactory.getLogger(this.getClass());

	@Resource(name = "dataAuthWebService")
	private MDataAuthWebService dataAuthWebService;

	/**
	 * 跳转到 申请信息界面
	 */
	@RequestMapping(value = "view_apply_auth")
	public ViewAndModel view_apply_auth() {
		log.debug(" dataAuth   方法  consumerview  调用");
		ViewAndModel model = new ViewAndModel(request, cache);
		model.setViewName("data_auth/applyAuth");
	
		return model;
	}
	/**
	 * 跳转到 数据列表界面
	 */
	@RequestMapping(value = "view_auth_page")
	public ViewAndModel view_auth_page() {
		log.debug(" dataAuth   方法  consumerview  调用");
		ViewAndModel model = new ViewAndModel(request, cache);
		model.setViewName("data_auth/authPage");
	
		return model;
	}
	/**
	 * 跳转到 数据列表界面
	 */
	@RequestMapping(value = "view_auth_apply_page")
	public ViewAndModel view_auth_apply_page() {
		log.debug(" dataAuth   方法  consumerview  调用");
		ViewAndModel model = new ViewAndModel(request, cache);
		model.setViewName("data_auth/authApplyPage");
	
		return model;
	}
	/**
	 * 数据列表
	 * 
	 * @param form
	 * @return
	 * @throws IOException
	 */
	@ResponseBody
	@RequestMapping(value = "query_auth_apply_page")
	public ResultListVO<MDataAuthorityVO> query_auth_apply_page(MDataAuthorityForm form) throws IOException {
		log.info("数据授权申请界面列表form={}",form);
		return dataAuthWebService.queryApplyPage(form,this.loginConsumer());
	}
	/**
	 * 数据列表
	 * 
	 * @param form
	 * @return
	 * @throws IOException
	 */
	@ResponseBody
	@RequestMapping(value = "query_auth_page")
	public ResultListVO<MDataAuthorityVO> query_auth_page(MDataAuthorityForm form) throws IOException {
		log.info("数据授权列表form={}",form);
		return dataAuthWebService.queryPage(form);
	}
	/**
	 * 申请权限
	 * 
	 * @param form
	 * @return
	 * @throws IOException
	 */
	@ResponseBody
	@RequestMapping(value = "applyAuth")
	public ResultBooleanVO applyAuth(MDataAuthorityForm form) throws IOException {
		log.info("申请数据授权form={}",form);
		return dataAuthWebService.grantAuth(form, loginConsumer());
	}

	/**
	 * 判断权限
	 * 
	 * @param form
	 * @throws IOException
	 */
	@ResponseBody
	@RequestMapping(value = "judgeAuth")
	public ResultBooleanVO judgeAuth(MDataAuthorityForm form) throws IOException {
		log.info("判断数据下载权限form={}",form);
		return dataAuthWebService.judgeAuth(form, loginConsumer());
	}
	/**
	 * 赋予权限
	 * 
	 * @param form
	 * @return
	 * @throws IOException
	 */
	@ResponseBody
	@RequestMapping(value = "passAuth")
	public ResultBooleanVO passAuth(Long id) throws IOException {
		log.info("通过数据下载权限id={}",id);
		return dataAuthWebService.passAuth(id, loginConsumer());
	}
	/**
	 * 赋予权限
	 * 
	 * @param form
	 * @return
	 * @throws IOException
	 */
	@ResponseBody
	@RequestMapping(value = "noPassAuth")
	public ResultBooleanVO noPassAuth(Long id) throws IOException {
		log.info("不通过数据下载权限id={}",id);
		return dataAuthWebService.noPassAuth(id, loginConsumer());
	}
}
